/*
 * CArmorPenReduction.java
 * 
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 * 
 * This file is part of Expression program is undefined on line 8, column 40 in Templates/Licenses/license-gplv3.txt..
 * 
 * Expression program is undefined on line 10, column 19 in Templates/Licenses/license-gplv3.txt. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Expression program is undefined on line 15, column 19 in Templates/Licenses/license-gplv3.txt. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Expression program is undefined on line 21, column 30 in Templates/Licenses/license-gplv3.txt..  If not, see <http://www.gnu.org/licenses/>.
 */

package dpssystem;

/**
 *
 * @author Mani
 */
public class CArmorPenReduction {
    CSim m_sim;
    double m_armorPenMajorDebuff = 1.0;
    double m_armorPenMinorDebuff = 1.0;
    double m_maceSpecialization;
    double m_reducedArmor;
    double m_constant = ((467.5 * 80.0) - 22167.5); // Constant
    double m_tempA;

    // TODO Armor cap of 100% as of 3.1.2
    CArmorPenReduction(CSim p_sim)
    {
        m_sim = p_sim;
        m_armorPenMajorDebuff -= p_sim.m_dpsInterface.m_raidBuffs.getArmorPenMajor(); // 10%
        m_armorPenMinorDebuff -= p_sim.m_dpsInterface.m_raidBuffs.getArmorPenMinor(); // 5%

        m_maceSpecialization = p_sim.m_dpsInterface.m_talents.getMaceSpecializationDouble() * 3;

        double l_debuffPercent = m_armorPenMajorDebuff * m_armorPenMinorDebuff;
        double l_bossArmor = (double) m_sim.m_dpsInterface.m_target.getArmor() - ((8.0/3.0)* 80 * p_sim.m_dpsInterface.m_talents.getSerrateBlades());

        m_tempA = m_constant + l_bossArmor * l_debuffPercent;
        double l_termA = ((l_debuffPercent * l_bossArmor + m_constant) / 3.0);
        double l_termB = l_bossArmor * l_debuffPercent;
        if (l_termA < l_termB)
        {
            m_reducedArmor = l_termA;
        }
        else
        {
            m_reducedArmor = l_termB;
        }
    }

    public double getDamageReduction(double p_damage, boolean m_mace)
    {
        double l_personalArpPercent = m_sim.m_baseStats.getArmorPenPercent();

        if (m_mace)
        {
            // Mace specialization if mace equipped
            l_personalArpPercent += m_maceSpecialization;
        }

        double l_finalArmor = m_reducedArmor * l_personalArpPercent;

        double l_mitigation = (1.0 - (m_constant / (m_tempA - l_finalArmor)));
        return (p_damage * l_mitigation);
    }
}
